﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Collections;

namespace TST.SharePointObjects
{
    internal class BaseList
    {
        private List<BaseObject> _objects;
        private LicensingMode _licensingMode;

        protected LicensingMode LicensingMode
        {
            get { return _licensingMode; }
        }

        internal BaseList(LicensingMode licensingMode)
        {
            _objects = new List<BaseObject>();
            _licensingMode = licensingMode;
        }

        protected virtual void doLoadFromWeb(SPWeb web)
        {
        }

        protected virtual void doLoadFromWeb(SPWeb web, string groupFilter, string nameSearch)
        {
        }

        public void LoadFromWeb(SPWeb web)
        {
            if (web == null)
                return;
            Clear();
            doLoadFromWeb(web);
        }

        public void LoadFromWeb(SPWeb web, string groupFilter, string nameSearch)
        {
            if (web == null)
                return;
            Clear();
            doLoadFromWeb(web, groupFilter, nameSearch);
        }

        public void Clear()
        {
            _objects.Clear();
        }

        public void Add(BaseObject baseObject)
        {
            _objects.Add(baseObject);
        }

        public List<BaseObject> Items
        {
            get
            {
                return _objects;
            }
        }

        public BaseObject GetItemById(string id)
        {
            foreach (BaseObject obj in _objects)
            {
                if (string.Compare(obj.Id, id, true) == 0)
                {
                    return obj;
                }
            }
            return null;
        }

        protected List<BaseObject> Objects
        {
            get { return _objects; }
        }

    }
}
